package ru.papergames.web.listeners;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.papergames.common.form.PcPlayerForm;
import ru.papergames.web.AppConstants;
import ru.papergames.web.cache.PlayersManager;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @author Alexander Troshanin
 */
public class SessionListener implements HttpSessionListener {
	private static Log log = LogFactory.getLog(SessionListener.class);

	public void sessionCreated(HttpSessionEvent se) {
	}

	public void sessionDestroyed(HttpSessionEvent se) {
		PcPlayerForm player = (PcPlayerForm) se.getSession().getAttribute(AppConstants.SESSION_USER);
        if (player == null) {
            return;
        }
        PlayersManager.getInstance().removeActivePlayerAfterLogof(player);
	}
}
